import axios from "@/libs/request";
import { getToken } from "@/libs/util";
// export const login = ({ userName, password,code,sid }) => {
//   const data = {
//     userName,
//     password,
//     code,
//     sid
//   }
//   return axios.request({
//     url: '/login/alogin',
//     data,
//     method: 'post'
//   })
// }

const getUserInfo = () => {
  return axios.get("/public/info", {
    headers: {
      Authorization: "Bearer " + getToken(),
    },
  });
};

const logout = (token) => {
  return axios.request({
    url: "logout",
    method: "post",
  });
};

const getUnreadCount = () => {
  return axios.request({
    url: "message/count",
    method: "get",
  });
};

const getMessage = () => {
  return axios.request({
    url: "message/init",
    method: "get",
  });
};

const getContentByMsgId = (msg_id) => {
  return axios.request({
    url: "message/content",
    method: "get",
    params: {
      msg_id,
    },
  });
};

const hasRead = (msg_id) => {
  return axios.request({
    url: "message/has_read",
    method: "post",
    data: {
      msg_id,
    },
  });
};

const removeReaded = (msg_id) => {
  return axios.request({
    url: "message/remove_readed",
    method: "post",
    data: {
      msg_id,
    },
  });
};

const restoreTrash = (msg_id) => {
  return axios.request({
    url: "message/restore",
    method: "post",
    data: {
      msg_id,
    },
  });
};

const login = (logininfo) => {
  return axios.request({
    url: "/login/alogin",
    method: "post",
    data: {
      ...logininfo,
    },
  });
};

const getUserComms = () => {
  return axios.get("/admin/getAllcomm", {
    headers: {
      Authorization: "Bearer " + getToken(),
    },
  });
};

const delComm = (ids) => {
  return axios.get("/admin/delcomm", {
    params: {
      ids: ids,
    },
  });
};
const getUser = () => {
  return axios.get("/admin/getuser", {});
};
const delUser = (ids) => {
  return axios.get("/admin/delUser", {
    params: {
      ids: ids,
    },
  });
};

const getSerch = (type, value) => {
  return axios.get("/admin/serch", {
    params: {
      type: type,
      value: value,
    },
  });
};

const getStatData = () => {
  return axios.get("/admin/getstat");
};
export {
  getUserComms,
  delComm,
  login,
  restoreTrash,
  removeReaded,
  hasRead,
  getContentByMsgId,
  getMessage,
  getUnreadCount,
  logout,
  getUserInfo,
  getUser,
  delUser,
  getSerch,
  getStatData,
};
